import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
// import whoami from '@dfeidao/atom-web/msg/whoami';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import render from '@dfeidao/atom-web/render/render';
import a001 from './a001';
import P06 from './P06';
export default async function a004(fd: IFeidaoAiBrowserComponent) {
	// 完成
	// const userinf = await whoami();
	const productid = get(fd, 'productid');
	// const usercode = userinf.usercode;
	// const username = userinf.user_name;
	const num = get(fd, 'number');
	const level_name = fd.data.node.querySelector<HTMLInputElement>('[uodateinput1]').value;
	const update = fd.data.node.querySelector<HTMLDivElement>('[uodateinput]');
	update.classList.remove('display-n');
	if (!level_name) {
		update.classList.add('display-n');
		return;
	}
	if (num === 1) {
		const res = await nodejs('level-inf/zj-000001/s003', { level_name, productid });
		if (res === 'success') {
			success('成功');
			update.classList.add('display-n');
			await a001(fd);
		} else if (res === 'fail') {
			error('失败');
		} else {
			fire('zj-000004', 'ec-001');
		}
	} else {
		const level_no = get(fd, 'level_no');
		const res = await nodejs('level-inf/zj-000001/s004', { level_name, level_no, productid });
		if (res === 'success') {
			success('成功');
			update.classList.add('display-n');
			await a001(fd);
		} else if (res === 'fail') {
			error('失败');
		} else {
			fire('zj-000004', 'ec-001');
		}
	}
	render(fd, '', P06, "P06", "inner");
}
